package com.jk.controller;

import com.jk.entity.Product;
import com.jk.entity.ProductSeckill;
import com.jk.entity.Shoptype;
import com.jk.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller

public class ProductController {

    @Autowired
    private ProductService productService;

    @ResponseBody
    @RequestMapping("getPro")
    public List<Product> getListPro(){

        List<Product> listPro = productService.getListPro();
        System.out.println(listPro);
        return listPro;

    }
    @ResponseBody
    @RequestMapping("getPro2")
    public List<Product> getListPros(){

        List<Product> listPro = productService.getListPros();
        System.out.println(listPro);
        return listPro;

    }
    @ResponseBody
    @RequestMapping("getProOne")
    public List<Product> getProOne(Integer id){

        List<Product> listPro = productService.getProOne(id);
        System.out.println(listPro);
        return listPro;

    }

   @RequestMapping("gou")
    public  void  gou(HttpServletResponse httpResponse, HttpServletRequest request,String id,String address,String cphone,String cname,String couponId) throws IOException {
      productService.gou(httpResponse,request,id,address,cphone,cname,couponId);
    }

    @ResponseBody
    @RequestMapping("seckill")
    public  List<ProductSeckill>  seckill() {
       return productService.seckill();
    }
    @RequestMapping("seckill22")
    @ResponseBody
    public  List<ProductSeckill>  seckill22() {
       return productService.seckill22();
    }
    @ResponseBody
    @RequestMapping("seckillOne")
    public  List<ProductSeckill>  seckillOne(String id) {
       return productService.seckillOne(id);
    }


    @ResponseBody
    @RequestMapping("seckillProduct")
    public  void  seckillProduct(HttpServletResponse httpResponse, Integer id,HttpServletRequest request,String cname,String address,String cphone) throws IOException {
        productService.seckillProduct(httpResponse,id,request,cname,address,cphone);
    }


    @RequestMapping("seckillProductPay")
    public void pay(HttpServletRequest request,HttpServletResponse response) {
        productService.seckillProductPay(request);
        try {
            response.sendRedirect("index.html");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    @RequestMapping("pay2")
    public void pay2(HttpServletRequest request,HttpServletResponse response) {
        productService.Pay2(request);
        try {
            response.sendRedirect("index.html");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }




    @ResponseBody
    @RequestMapping("getProOness")
    public List<Shoptype> getProOness(Integer id){

        List<Shoptype> listPro = productService.getProOness(id);
        System.out.println(listPro);
        return listPro;

    }
    @ResponseBody
    @RequestMapping("getTypeOne")
    public List<Shoptype> getTypeOne(Integer id){

        List<Shoptype> listPro = productService.getTypeOne(id);
        System.out.println(listPro);
        return listPro;

    }
    @ResponseBody
    @RequestMapping("getPros1")
    public List<Product> getPros1(Integer id){

        List<Product> listPro = productService.getPros1(id);
        System.out.println(listPro);
        return listPro;

    }
}
